﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using CMN.Models;
using CMN.Models.Interfaces;
using CMN.Entity;
using System.Web.Routing;
using CMN.Common;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using CMN.Controllers.Filters;
using CMN.Framework;
using System.Collections;
namespace CMN.Controllers
{
    [ExceptionFilter]
    [LoggerFilter]
    [UserAuthorize]
    public class Normal_ClearnCacheController : Controller
    {
        
        // 返回json字符串
        protected string returnJson = string.Empty;

        /// <summary>
        /// 转到View页面
        /// </summary>
        /// <returns></returns>
        public ViewResult Index()
        {
            return View("Index");//页面地址
        }


        /// <summary>
        /// 删除所有缓存
        /// </summary>
        /// <returns></returns>
        public string ClearnAll()
        {
            IDictionaryEnumerator id = HttpRuntime.Cache.GetEnumerator();
            while (id.MoveNext())
            {
                DictionaryEntry abc = id.Entry;
                string Tempstring = (string)id.Key;
                HttpRuntime.Cache.Remove(Tempstring);
            }
            Utils.DeleteFolder(string.Concat(Utils.GetServerPath(), "App_Data\\cache\\"));
             returnJson = string.Concat("{totalPorperty:", "1", ",message:\"已经删除所有缓存完毕\"}");
          return returnJson;
        }

        /// <summary>
        /// 删除所有HTML
        /// </summary>
        /// <returns></returns>
        public string ClearnHTML()
        {

            Utils.DeleteFolder(string.Concat(Utils.GetServerPath(), "App_Data\\cache\\"));
             returnJson = string.Concat("{totalPorperty:", "1", ",message:\"已经删除所有HTML完毕\"}");
            return returnJson;
        }
        /// <summary>
        /// 删除首页html
        /// </summary>
        /// <returns></returns>
        public string ClearnDefaultHTML()
        {
           Utils.DeleteFile(string.Concat(Utils.GetServerPath(), "App_Data\\html\\default.htm"));
           returnJson = string.Concat("{totalPorperty:", "1", ",message:\"已经删除首页html完毕\"}");
            return returnJson;
        }

        /// <summary>
        /// 删除友情链接缓存
        /// </summary>
        /// <returns></returns>
        public string ClearnLinkHTML()
        {
          Utils.DeleteFolder( string.Concat(Utils.GetServerPath(), "App_Data\\cache\\Normal_Link\\"));
            returnJson = string.Concat("{totalPorperty:", "1", ",message:\"已经删除友情链接缓存完毕\"}");
            return returnJson;
        }
      

       

    }
}
